<?php

namespace app\index\controller;


use app\common\modelMsg\LogMessageReceive;

class Index
{
    public function index()
    {
        return view('index');
    }

    public function add()
    {
        $log = new LogMessageReceive();

        $log->data([
            'info' => 'this is test'
        ]);

        dump($log->save());
    }


    public function getItem()
    {
        $log = new LogMessageReceive();

        $data = $log->where(['id' => 1])->find();

        dump($data->toArray());

    }

    public function update()
    {
        $log = new LogMessageReceive();
        $result = $log->save([
            'info' => 'this is update'
        ], ['id' => 1]);

        dump($result);
    }

    public function updateAll()
    {
        $log = new LogMessageReceive();
        $result = $log->field(['id', 'info'])->select()->toArray();

        foreach ($result as $k =>  $item) {
            $result[$k]['info'] = 'this is update message' . time();
        }

        $result = $log->isUpdate()->saveAll($result);
        // 这是更新后的数据
        $result = $result->toArray();
        dump($result);
    }


    public function updateCount()
    {
        $log = new LogMessageReceive();
        $data = $log->where(['id' => 1])->find()->toArray();
        dump($data);
        die();

        $result = $log->save([
            'info' => 'this is update'
        ], ['id' => 1]);
    }


}
